import http from '../utils/http';

/**
 * 获取列表
 */
function getDims(){
    return new Promise((resolve, reject) => {
        http("get",'/dim/dims').then(res => {
            //console.log("ap-------:"+res);
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

/**
 * 获取列表
 */
function getDims2(){
    return new Promise((resolve, reject) => {
        http("get",'/dim/dims2').then(res => {
            //console.log("ap-------:"+res);
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function getTheMbr(dimId,mbrId) {
    let param={dimId:dimId,mbrId:mbrId}
    return new Promise((resolve, reject) => {
        http("get",'/dim/getTheMember',{dimId:dimId,mbrId:mbrId}).then(res => {
            //console.log("ap-------:"+res);
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}


function getDimMbrs(dimType){
    let param={dimType:dimType}
    return new Promise((resolve, reject) => {
        http("get",'/dim/getDimMbrTree',param).then(res => {
            //console.log("ap-------:"+res);
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function saveDimMember(memberInfo){
    //let param={memberInfo:memberInfo}
    return new Promise((resolve, reject) => {
        http("post",'/dim/saveDimMember',memberInfo).then(res => {
            //console.log("ap-------:"+res);
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function getMembersByDimId(dimId){
    let param={dimId:dimId}
    return new Promise((resolve, reject) => {
        http("get",'/dim/getMembersByDimId',param).then(res => {
            //console.log("ap-------:"+res);
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function validateMemberFormula(formulaText,dimId){
   // let param={formulaText:formulaText,dimId:dimId}
    let param={memberFormulaContent:formulaText,dimId:dimId}
    return new Promise((resolve, reject) => {
        http("post",'/dim/validateMemberFormula',param).then(res => {
            //console.log("ap-------:"+res);
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function delDimMbr(dimMbrId,dimId){
    let param={dimMbrId:dimMbrId,dimId:dimId,}
    return new Promise((resolve, reject) => {
        http("post",'/dim/deleteMember',param).then(res => {
            //console.log("ap-------:"+res);
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}


export {
    getDims,getDims2,getDimMbrs,saveDimMember,getMembersByDimId,validateMemberFormula,delDimMbr,getTheMbr
}

